package com.atguigu.srb.core.controller.api;


import com.atguigu.srb.base.result.ResponseVo;
import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.core.pojo.entity.Borrower;
import com.atguigu.srb.core.pojo.entity.vo.BorrowerVO;
import com.atguigu.srb.core.service.BorrowerService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.xml.ws.Response;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2024-10-11
 */
@RestController
@RequestMapping("/api/core/borrower")
public class ApiBorrowerController {

    @Resource
    BorrowerService borrowerService;

    @ApiOperation("提交借款人数据")
    @PostMapping()
    public ResponseVo save(@RequestBody BorrowerVO borrowerVO,
                           @RequestHeader(value = "token",required = false)String token){
        borrowerService.saveBorrowrVO(borrowerVO,token);
        return ResponseVo.ok().message("保存成功");
    }

    @ApiOperation("查询借款人申请状态 状态（0：未认证，1：认证中， 2：认证通过， -1：认证失败）")
    @GetMapping("status")
    public ResponseVo borrowerStatus(@RequestHeader(value = "token",required = false)
                                         String token){
        Long userId = JwtUtils.getUserId(token);
        Borrower borrower = borrowerService.getOne(Wrappers.lambdaQuery(Borrower.class)
                .eq(Borrower::getUserId, userId));
        return ResponseVo.ok().data("status",borrower==null?0:borrower.getStatus());
    }

}

